package util;

import static java.lang.Math.hypot;

public class Vec2I
{
	static int Distance2(final Vec2I v1,final Vec2I v2)
	{
		return v1.sub(v2).mag2();
	}
	static double Distance(final Vec2I v1,final Vec2I v2)
	{
	    return hypot(v1.x-v2.x,v1.y-v2.y);
	}
	
	private final int x,y;
	
	public Vec2I(int x,int y)
	{
		this.x=x;
		this.y=y;
	}
	public Vec2I(Vec2I vec)
	{
		this.x=vec.x;
		this.y=vec.y;
	}
	
	public Vec2I(Vec2F location)
	{
		this.x = (int) location.getX();
		this.y = (int) location.getY();
	}
	public Vec2I(double x, double y)
	{
		this.x = (int) x;
		this.y = (int) y;
	}
	final public int getX() {
		return x;
	}
	final public int getY() {
		return y;
	}

	public static Vec2I add(Vec2I v1,Vec2I v2)
	{
		return new Vec2I(v1.x+v2.x,v1.y+v2.y);
	}
	public static Vec2I sub(Vec2I v1,Vec2I v2)
	{
		return new Vec2I(v1.x-v2.x,v1.y-v2.y);
	}
	public static int dot(Vec2I v1,Vec2I v2)
	{
		return v1.x*v2.x+v1.y*v2.y;
	}
	public static Vec2I scale(Vec2I v1,int scale)
	{
		return new Vec2I(v1.x*scale,v1.y*scale);
	}
	public static Vec2F scale(Vec2I v1,float scale)
	{
		return new Vec2F(v1.x*scale,v1.y*scale);
	}
	
	/**
	 * Assumes counter-clockwise is positive ie. if v2 is counter-clockwise from
	 * v1 then the result will be positive.
	 * @author Stephen Pheiffer
	 * @param v1
	 * @param v2
	 * @return sin of angle between v1 and v2.
	 */
	public static int cross(Vec2I v1, Vec2I v2)
	{
		return (v1.x * v2.y) - (v1.y * v2.x);
	}
	public boolean equals(Vec2I v1)
	{
		return v1.x==x && v1.y==y;
		
	}
	public Vec2I add( Vec2I v2)
	{
		return new Vec2I(x+v2.x,y+v2.y);
	}
	public Vec2I sub(Vec2I v2)
	{
		return new Vec2I(x-v2.x,y-v2.y);
	}
	public int dot(Vec2I v2)
	{
		return x*v2.x+y*v2.y;
	}
	public Vec2I scale(int scale)
	{
		return new Vec2I(x*scale,y*scale);
	}
	public Vec2F scale(float scale)
	{
		return new Vec2F(x*scale,y*scale);
	}
	public Vec2F scale(Vec2I scale)
	{
		return new Vec2F(x*scale.getX(),y*scale.getY());
	}
	public Vec2F scale(Vec2F scale)
	{
		return new Vec2F(x*scale.getX(),y*scale.getY());
	}
	
	/**
	 * Get orthogonal vector (rotated clockwise)
	 * @author Stephen Pheiffer
	 * @return
	 */
	public Vec2I ortho()
	{
		return new Vec2I(-y,x);
	}
	public int mag2()
	{
		return x*x+y*y;
	}
	public double mag()
	{
		return hypot(x,y);
	}
	@Override
	public String toString()
	{
		return String.format("%d , %d", x,y);
	}
	@Override
	public int hashCode()
	{
		return x * y;
	}
}
